package com.zmj.sy.mom.srv.aps.controller;

import com.zmj.sy.mom.srv.aps.bean.dto.GroupUser.GroupUserDto;
import com.zmj.sy.mom.srv.aps.bean.dto.staff.StaffDto;
import com.zmj.sy.mom.srv.aps.bean.dto.staff.TeamSelectDto;
import com.zmj.sy.mom.srv.aps.bean.vo.base.*;
import com.zmj.sy.mom.srv.aps.bean.vo.group.*;
import com.zmj.sy.mom.srv.aps.bean.vo.grouprefactor.GroupAddResVo;
import com.zmj.sy.mom.srv.aps.service.GroupService;
import com.zmj.sy.mom.srv.aps.service.GroupUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequiredArgsConstructor
@Api(tags = "组")
@RestController
@RequestMapping("/group")
public class GroupController {


    private final GroupService groupService;
    private final GroupUserService groupUserService;

    @ApiOperation("1.4.1 新增组")
    @PostMapping("/add")
    public GroupAddResVo add(@RequestBody GroupAddReqVo reqVo){
        Integer id = groupService.add(reqVo);
        GroupAddResVo resVo = new GroupAddResVo();
        resVo.setSourceId(id);
        return resVo;
    }

    @ApiOperation("1.4.2 组列表")
    @GetMapping("/list")
    public BasePageResVo<GroupListResVo> list(GroupListReqVo reqVo){
        return groupService.list(reqVo);
    }

    @ApiOperation("1.4.4 查看组")
    @GetMapping("/get")
    public GroupGetResVo get(BaseIdReqVo reqVo){
        return groupService.get(reqVo);
    }

    @ApiOperation("1.4.5 修改组")
    @PostMapping("/edit")
    public BaseResVo edit(@RequestBody GroupAddReqVo reqVo){
        groupService.edit(reqVo);
        return BaseResVo.ok();
    }

    @ApiOperation("1.4.6 删除组")
    @PostMapping("/delete")
    public BaseResVo delete(BaseIdReqVo reqVo){
        groupService.delete(reqVo);
        return BaseResVo.ok();
    }

    @ApiOperation("1.4.7 分组下拉框")
    @GetMapping("/select")
    public BaseSelectResVo select(GroupSelectReqVo reqVo) {
        return groupService.select(reqVo);
    }

    @ApiOperation("1.4.11 根据工序查询工作组 ")
    @GetMapping("/selectPhase")
    public BaseSelectResVo selectPhase(GroupSelectReqVo reqVo) {
        return groupService.selectPhase(reqVo);
    }

    @ApiOperation("1.4.8 人员查询列表")
    @GetMapping("/staffSelect")
    public Result<List<StaffDto>> staffSelect(StaffDto staffDto) {
        List<StaffDto> list = groupUserService.staffDtoList(staffDto);
        return Result.success(list);
    }


    @ApiOperation("1.4.9 查看人员-组列表")
    @GetMapping("/getStaffGroup")
    public Result<List<GroupUserDto>> get(Integer groupId){
//        return groupService.get(reqVo);
        List<GroupUserDto> listResult = groupUserService.getGroupUser(groupId);
        return Result.success(listResult);
    }

    @ApiOperation("1.4.10 查看班组列表")
    @GetMapping("/getTeamList")
    public Result<List<TeamSelectDto>> get(TeamSelectDto dto){
        List<TeamSelectDto> listResult = groupUserService.getTeamList(dto);
        return Result.success(listResult);
    }



}
